//package com.qys.livesMall.security.interceptor.core;
//
//
//
//import lombok.extern.slf4j.Slf4j;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.core.annotation.Order;
//import org.springframework.util.StringUtils;
//import org.springframework.web.servlet.HandlerInterceptor;
//import org.springframework.web.servlet.ModelAndView;
//
//import javax.servlet.http.HttpServletRequest;
//import javax.servlet.http.HttpServletResponse;
//import java.io.IOException;
//import java.io.PrintWriter;
//import java.util.Objects;
//
//@Slf4j
//@Order(4)
//public class IpInterceptor implements HandlerInterceptor {
//
//
//    @Autowired
//    private SysParamConfigInfoService sysParamConfigInfoService;
//
//    //handle 前
//    @Override
//    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
//            throws Exception {
//        logger.info("***********************IP拦截器*************************");
//        //如果是登录请求，跳过验证
//        String url=request.getRequestURI();
//
//
//        User user= UserInfoThreadHolder.getCurrentUser();
//
//        Result jsonResult=null;
//        boolean pass=true;
//        String ipOnOff=sysParamConfigInfoService.getParam(SysParamConstants.IP_ON_OFF);
//        if (!StringUtils.isEmpty(ipOnOff) && Objects.equals(SysParamConstants.YesNo.YES,ipOnOff)) {
//            //ip验证
//            String ip = IpUtil.getIpAddr(request);
//
//            boolean ipExist = ipConfigService.isExist(ip);
//            if (!ipExist) {
//                //未登陆向前端返回数据
//                System.err.print("无效ip:" + ip);
//                jsonResult = Result.fail("402", "无效地址");
//                pass = false;
//            }
//
//            if (!pass) {
//                String jsonString = JSONObject.toJSONString(jsonResult);
//                PrintWriter writer = null;
//                response.setCharacterEncoding("UTF-8");
//                response.setContentType("text/html; charset=utf-8");
//                try {
//                    writer = response.getWriter();
//                    writer.print(jsonString);
//
//                } catch (IOException e) {
//                    logger.info("无权访问资源", e);
//                } finally {
//                    if (writer != null)
//                        writer.close();
//                }
//                return false;
//            }
//        }
//        //user.getUserId()
//            return true;
//        }
//
//
//
//
//    @Override
//    public void postHandle(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Object o, ModelAndView modelAndView) throws Exception {
//
//    }
//
//
//    //controller 后
//    @Override
//    public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
//            throws Exception {
//        // TODO Auto-generated method stub
//
//    }
//}
